package com.alibaba.citrus.ots.sales.plan.converter;

import com.alibaba.citrus.ots.sales.plan.model.features.SalesPlanScItemFeatures;
import com.alibaba.citrus.ots.sales.plan.sdo.SalesPlanScItemExtendSDO;
import com.alibaba.citrus.ots.sales.plan.sdo.SalesPlanStatScItemSDO;
import com.alibaba.fastjson.JSONObject;
import com.epoch.app.bcots.sales_plan.planscitem.model.PlanScItem;
import com.epoch.app.bcots.sales_plan.planscitemextend.model.PlanScItemExtend;
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.Objects;

/**
 * @author zls
 * @date 2021/10/15 12:42 上午
 */
public class PlanScItemExtendConverter {


    public static PlanScItemExtend planScItemExtendSdoToDo(SalesPlanScItemExtendSDO request){
        if (Objects.isNull(request)){
            return null;
        }
        PlanScItemExtend target = new PlanScItemExtend();
        BeanUtils.copyProperties(request,target);
        SalesPlanScItemFeatures features = new SalesPlanScItemFeatures();
/*        features.setScItemName(request.getScItemName());*/
        target.setFeatures(JSONObject.toJSONString(features));
        return target;
    }

    public static SalesPlanScItemExtendSDO planScItemExtendDoToSdo(PlanScItemExtend request){
        if (Objects.isNull(request)){
            return null;
        }
        SalesPlanScItemExtendSDO target = new SalesPlanScItemExtendSDO();
        BeanUtils.copyProperties(request,target);
        if (!Objects.isNull(request.getFeatures())){
            SalesPlanScItemFeatures features = JSONObject.parseObject(request.getFeatures(), SalesPlanScItemFeatures.class);
/*            target.setScItemName(features.getScItemName());*/
        }
        return target;
    }

    public static List<PlanScItemExtend> planScItemExtendSdoToDo(List<SalesPlanScItemExtendSDO> requestList){
        if (CollectionUtils.isEmpty(requestList)){
            return null;
        }
        List<PlanScItemExtend> result = Lists.newArrayListWithCapacity(requestList.size());
        for (SalesPlanScItemExtendSDO request : requestList) {
            result.add(planScItemExtendSdoToDo(request));
        }
        return result;
    }

    public static List<SalesPlanScItemExtendSDO> planScItemExtendDoToSdo(List<PlanScItemExtend> requestList){
        if (CollectionUtils.isEmpty(requestList)){
            return null;
        }
        List<SalesPlanScItemExtendSDO> result = Lists.newArrayListWithCapacity(requestList.size());
        for (PlanScItemExtend request : requestList) {
            result.add(planScItemExtendDoToSdo(request));
        }
        return result;
    }


}
